<?php 
/////////////////////////////////////////////////////////////////////////////////////		
include "required_code.php"; 

				session_start();
				$ses_user_id =$_SESSION['ses_user_id'];
				$ses_std_id = $_SESSION['ses_std_id'];
				$concept=$_SESSION['concept'];
				$round=$_SESSION['round'];
				$ls=$_SESSION['ls'];
				if($ses_user_id <> session_id() or  $ses_std_id ==''){
					echo "Authentication failed";
					echo "<meta http-equiv='refresh' content='2;URL=index.php' />";
					}    
					
							$query2="SELECT * FROM fa_test_progress WHERE std_id=$ses_std_id AND concept=$concept";
							$db_result2=db_query($query2);
							$result2=mysql_fetch_array($db_result2);
							//echo $result2['pretest_sts'];
							if($round==1 AND $result2['fa1']==""){
								echo "Redirecting";
								echo "<meta http-equiv='refresh' content='1;URL=progress.php' />";
							}
							
							else{
								
		/////////////////////////////////////////////////////////////////////////////////////						
						?>
						
						<table width="800" border="1" align="center" cellpadding="0" cellspacing="0">
						  <tr>
							<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
							  <tr>
								<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
								  <tr>
									<td width="23%" bgcolor="#FFFFFF"><?php include "header.html"; ?></td>
									</tr>
								</table></td>
							  </tr>
							  <tr>
								<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
								  <tr>
								   
									<td width="80%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
									  <tr>
										<td bgcolor="#00CCFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
										  <tr>
											<td><div align="left"><tt><a href="progress.php">Home</a> &gt; </tt><tt><a href="learning_paths.php">Learning Paths</a> &gt; <a href="concept_progress.php">
                                            <?php call_concept_name($concept); ?>
[R<?php echo $round; ?>/2]</a> &gt; Test Result</tt></div></td>
											<td>&nbsp;</td>
											<td><?php include "right_navi.php"; ?></td>
										  </tr>
										</table></td>
									  </tr>
									  <tr>
										<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
										  <tr>
											<td bgcolor="#FFFFFF"><br />
											  <table width="100%" border="0" cellspacing="0" cellpadding="5">
												<tr>
												  <td>
                                                  <?php ///////////////////////////PRETEST RESULT///////////////////////////////
			$sum=0;
			for ($i=1;$i<=$fa_test_item;$i++){
					$query2="SELECT * FROM std_fa_ans_r1 WHERE std_id='".$ses_std_id."' AND concept='".$concept."' AND test_item='".$i."'";
					$db_result2=db_query($query2);
					$result2=mysql_fetch_array($db_result2);
					$result2['test_ans'];
					$query3="SELECT * FROM fa_test_items WHERE concept='".$concept."' AND item='".$i."'";
					$db_result3=db_query($query3);
					$result3=mysql_fetch_array($db_result3);
					$result3['ans'];

						if($result2['test_ans'] == $result3['ans'] && $result2['test_ans']!="") {
							$query_insert_test_result="UPDATE std_fa_ans_r1 SET test_result='1' WHERE std_id='".$ses_std_id."' AND concept='".$concept."' AND test_item='".$i."'" ;
							db_query($query_insert_test_result);
							echo "Item ".$i." is CORRECT.<BR>";
							$sum++;
						}
						else{
							$query_insert_test_result="UPDATE std_fa_ans_r1 SET test_result='0' WHERE std_id='".$ses_std_id."' AND concept='".$concept."' AND test_item='".$i."'" ;
							db_query($query_insert_test_result);
							echo "Item ".$i." is WRONG.<BR>";

						}
				 }
				
				echo "<H3>Your '";
				call_concept_name($concept);
				echo "' Concept Test Score is ".$sum." / ".$fa_test_item.".</H3><hr>";
				
				
				if($sum>3){
						echo "PASSED";
						$query_status="UPDATE std_vs_concept SET status='1' WHERE std_id='".$ses_std_id."' AND concept='".$concept."'";
						db_query($query_status);
						if($round==1)
						$query_status="UPDATE fa_test_progress SET fa1='P' WHERE std_id='".$ses_std_id."' AND concept='".$concept."'";
						if($round==2)
						$query_status="UPDATE fa_test_progress SET fa2='P' WHERE std_id='".$ses_std_id."' AND concept='".$concept."'";
							db_query($query_status);
					 	echo " [<a href='learning_paths.php'>Go to Learning Paths</a>]";
						
				}
				else{
						
						//$_SESSION['round']=2;
						if($round==1){
						$query_status="UPDATE fa_test_progress SET fa1='F' WHERE std_id='".$ses_std_id."' AND concept='".$concept."'";
						echo "FAILED";
						}
						if($round==2){
						$query_status="UPDATE fa_test_progress SET fa2='F' WHERE std_id='".$ses_std_id."' AND concept='".$concept."'";
						echo "You finally FAILED this concept";
						}
							db_query($query_status);
						if($round==1)	
						echo " [<a href='learning_paths.php'>Go Back to learn additional material</a>]";
				}

				////////////////////////////PRETEST RESULT//////////////////////////////
				?></td>
												</tr>
												<tr>
												  <td></td>
												</tr>
												<tr>
												  <td></td>
												</tr>
											  </table></td>
										  </tr>
										</table></td>
									  </tr>
									</table></td>
								  </tr>
								</table></td>
							  </tr>
							  <tr>
								<td bgcolor="#FFFFFF"><?php include "footer.html"; ?></td>
							  </tr>
							</table></td>
						  </tr>
						</table>
						</body>
						</html>
						<?php
						/////////////////////////////////////////////////////////////////////////////////////		
							$db_close=db_disconnect($db_open);
							}
/////////////////////////////////////////////////////////////////////////////////////		
?>
